﻿using HKB.Common;
using HKB.Web.Admin;
using System;
using System.IO;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_managejs : Admin, IRequiresSessionState
{
    public decimal FileSize1 = 0m;
    public decimal FileSize2 = 0m;
    public decimal FileSize3 = 0m;
    public decimal FileSize4 = 0m;
    public decimal FileSize5 = 0m;
    public decimal FileSize6 = 0m;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(12))
        {
            base.WriteLog("Modify", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        this.GetFileSize();
        if (!base.IsPostBack)
        {
            if (base.Request.QueryString["ZoneType"] != null)
            {
                this.Panel1.Visible = false;
                this.Panel2.Visible = true;
                this.Session["JSFileName"] = base.Server.MapPath("..") + "\\AD\\" + base.Request.QueryString["ZoneType"].ToString();
                this.BandJsCode(this.Session["JSFileName"].ToString());
            }
            else
            {
                this.Panel2.Visible = false;
                this.Panel1.Visible = true;
            }
            if (!base.admin.CheckAdminPower(13))
            {
                this.Button2.Enabled = false;
            }
        }
    }
    protected void BandJsCode(string JsFileName)
    {
        using (StreamReader streamReader = new StreamReader(JsFileName, Encoding.Default))
        {
            string str;
            while ((str = streamReader.ReadLine()) != null)
            {
                TextBox expr_1A = this.TxtCode;
                expr_1A.Text = expr_1A.Text + str + "\r\n";
            }
            streamReader.Close();
        }
    }
    protected void GetFileSize()
    {
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Banner.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Banner.js");
            this.FileSize1 = fileInfo.Length / 1000L;
        }
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Pop.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Pop.js");
            this.FileSize2 = fileInfo.Length / 1000L;
        }
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Move.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Move.js");
            this.FileSize3 = fileInfo.Length / 1000L;
        }
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Fixed.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Fixed.js");
            this.FileSize4 = fileInfo.Length / 1000L;
        }
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Float.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Float.js");
            this.FileSize5 = fileInfo.Length / 1000L;
        }
        if (File.Exists(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Code.js"))
        {
            FileInfo fileInfo = new FileInfo(base.Server.MapPath("..") + "\\AD\\ADTemplate\\Template_Code.js");
            this.FileSize6 = fileInfo.Length / 1000L;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(13))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Ads");
        }
        if (File.Exists(this.Session["JSFileName"].ToString()))
        {
            File.Delete(this.Session["JSFileName"].ToString());
        }
        using (StreamWriter streamWriter = new StreamWriter(this.Session["JSFileName"].ToString(), false, Encoding.GetEncoding("GB2312")))
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(this.TxtCode.Text.Trim());
            streamWriter.WriteLine(stringBuilder);
            streamWriter.Flush();
            streamWriter.Close();
        }
        this.Panel2.Visible = false;
        this.Panel1.Visible = true;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Panel2.Visible = false;
        this.Panel1.Visible = true;
    }
}
